package com.mqz.rocketmq.consumer.component;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * 版权所有  copyright© 蒙大拿
 *
 * @author mqz
 * @date 2022/7/28
 * @about https://www.gitee.com/DemoMeng
 * @description
 */
@Component
@RocketMQMessageListener(consumerGroup = "MyConsumerGroup", topic = "broker-a")
@Slf4j
public class Consumer implements RocketMQListener<String> {
    @Override
    public void onMessage(String message) {
        System.out.println("Recived message: " + message);
        if(JSONUtil.isJson(message)){
            String str = JSONUtil.parseObj(message).getStr("body");
            String msg = new String(str.getBytes(StandardCharsets.UTF_8),StandardCharsets.UTF_8);
            log.info("msg: {}",msg);
        }
    }

    public void test(){
        System.out.println("12322222");
    }
}
